<!DOCTYPE html>
<html>
<head>
    <title>选择规程</title>
    #parse("sys/header.html")
</head>
<body>
<div id="rrapp" v-cloak>
    <div v-show="showList">
        <Row :gutter="16" style="margin: 8px 0px 0px 1px">
            <div class="buttons-group">
                #if($shiro.hasPermission("devplanmain:save"))
                <i-button type="info" @click="addPlanOp"><i class="fa fa-plus"></i>&nbsp;新增规程</i-button>
                <i-button type="error" @click="del"><i class="fa fa-trash-o"></i>&nbsp;删除</i-button>
                #end
            </div>
        </Row>
        <table id="jqGrid"></table>
    </div>
</div>
<script>
    $(function () {
        var planId = getQueryString("planId");
        var status = getQueryString("status");
        vm.planId = planId;
        vm.status = status;
        $("#jqGrid").Grid({
            url: '../devplanmain/listAllRelatedRule?planId=' + planId,
            colModel: [
                {label: '规程名称', name: 'ruleName', index: 'RULE_NAME'},
                {label: '版本', name: 'planVersion', index: 'PLAN_VERSION', width: 50},
                {label: '工序号或自编号', name: 'proce', index: 'DEV_PROCE_NO', width: 50},
                {label: '设备编码', name: 'deviceCode', index: 'DI.DEV_CODE', width: 90},
                {label: '设备名称', name: 'deviceName', index: 'DI.DEV_NAME', width: 90},
                {label: '内容', name: 'planCon', index: 'PLAN_CON', width: 60},
                {label: 'id', name: 'id', index: 'ID', key: true, hidden: true},
            ]
        })
    })
    var vm = new Vue({
        el: '#rrapp',
        data: {
            showList: true,
            planId: '',
            status: '',
            title: null,
            title_plan: '',
            devMaintenPlan: {},
            typeList: enumsToList('MAINTENPLAN_TYPE'),//类型
        },
        methods: {
            reload: function (event) {
                vm.showList = true;
                var page = $("#jqGrid").jqGrid('getGridParam', 'page');
                $("#jqGrid").jqGrid('setGridParam', {
                    postData: {},
                    page: page
                }).trigger("reloadGrid");
            },
            addPlanOp: function () {
                //获取审批通过规程
                openWindow({
                    type: 2,
                    title: '<i class="fa fa-list-ol"></i>添加规程',
                    content: '../device/addMaintainPlan.html?planId=' + vm.planId,
                    btn: ['确定', '取消'],
                    btn1: function (index) {
                        var iframeWin = window["layui-layer-iframe" + index];
                        var res = iframeWin.getDatas();
                        var ids = "";
                        for (var i = 0; i < res.length; i++) {
                            ids += res[i];
                            if (i < res.length - 1) {
                                ids += ",";
                            }
                        }
                        Ajax.request({
                            url: "../devplanrule/addData",
                            params: JSON.stringify({'planId': vm.planId, 'rules': ids}),
                            type: "POST",
                            contentType: "application/json",
                            async: false,
                            successCallback: function (r) {
                                alert('操作成功', function () {
                                    layer.close(index);
                                    vm.reload();
                                });
                            }
                        });
                    }
                })
            },
            del: function (event) {
                let ids = getSelectedRows("#jqGrid");
                if (ids == null) {
                    return;
                }
                confirm('确定要删除选中的记录？', function () {
                    Ajax.request({
                        url: "../devplanmain/deleteRule",
                        params: JSON.stringify({'planId': vm.planId,'ruleIds': ids}),
                        type: "POST",
                        contentType: "application/json",
                        successCallback: function () {
                            alert('操作成功', function (index) {
                                vm.reload();
                            });
                        }
                    });
                });
            }
        }
    });
    getDatas = function () {
        var id = getSelectedRows("#jqGrid");
        return id
    }
</script>
</body>
</html>
